<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.companyName"
        clearable
        placeholder="公司名称名称"
        style="width: 200px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />

      <el-select
        v-model="listQuery.state"
        placeholder="状态"
        clearable
        style="width: 150px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      >
        <el-option style="width: auto" label="待用" :value="0">待用</el-option>
        <el-option style="width: auto" label="在用" :value="1">在用</el-option>
        <el-option style="width: auto" label="被禁用" :value="-1">被禁用</el-option>
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="tableData"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="编号" prop="id" align="center" min-width="100">
        <template slot-scope="{row}">
          <span>{{ row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" prop="id" align="center" min-width="100">
        <template slot-scope="{row}">
          <span>{{ row.companyName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="APPID" class-name="status-col" min-width="100">
        <template slot-scope="{row}">
          {{ row.appId }}
        </template>
      </el-table-column>
      <el-table-column label="支付宝状态" min-width="100" align="center">
        <template slot-scope="{row}">
          <el-tag v-if="row.state === 0" type="primary">待使用</el-tag>
          <el-tag v-if="row.state === 1" type="success">在用</el-tag>
          <el-tag v-if="row.state === -1" type="danger">已被禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" class-name="status-col" min-width="100">
        <template slot-scope="{row}">
          {{ row.createTime }}
        </template>
      </el-table-column>
      <el-table-column label="更新时间" class-name="status-col" min-width="100">
        <template slot-scope="{row}">
          {{ row.updateTime }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" min-width="100px" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" :disabled="row.state!==0" @click="handleUpdate(row)">
            使用
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="alipay"
    />


  </div>
</template>

<script>
import { alipay, use } from '@/api/sys'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'Sysdict',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableData: [],
      total: 0,
      tableKey: 0,
      listQuery: {
        current: 1,
        size: 10,
        sysLabel: ''
      },
      sysDict: {
        id: undefined,
        gmtDatetime: new Date(),
        sysKey: '',
        sysLabel: '',
        sysValue: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        username: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      listLoading: false
    }
  },
  created() {
    this.alipay()
  },
  methods: {
    // 获取用户列表
    async alipay() {
      const res = await alipay(this.listQuery, this.listQuery.sysLabel)

      this.tableData = res.data.data.records
      this.total = res.data.data.total
    },
    handleFilter() {
      this.listQuery.current = 1
      this.alipay(this.listQuery)
    },
    async handleUpdate(row) {
      use({ id: row.id }).then(res => {
        if (res.data.code === 200) {
          this.$notify({
            title: '成功！',
            message: '使用成功',
            type: 'success',
            duration: 2000
          })
        } else {
          this.$notify({
            title: '错误！',
            message: '使用有误，请联系管理员',
            type: 'error',
            duration: 2000
          })
        }
        this.alipay()
      })
    }
  }
}
</script>

<style scoped>
.pic{
  width: 150px;
  margin-top: 10px;
  margin-left: 10px;
}
.ok{
  margin-left: 10px;
  margin-top: 10px;
  font-weight: 5 00;
  color:rgb(35, 248, 124)
}
.fail{
  margin-left: 10px;
  margin-top: 10px;
  font-weight: 5 00;
  color: rgb(240, 174, 76);
}
.info{
  margin-left: 10px;
  margin-top: 10px;
  font-weight: 5 00;
}
.info-name{
  margin-left: 50px;
  margin-top: 10px;
  color:rgb(172, 176, 177);
}
.title{
  margin-top: 10px;
  margin-left: 10px;
  font-size: 20px;
  font-weight: 400;
}
.box{
  margin-top: 10px;
  width: 100%;
  border: solid rgb(138, 219, 230) 2px;
}
.nick{
  font-size: 30px;
  font-weight: 600;
}
.link-top {
  margin-left: 10px;
  margin-top: 10px;
  width: 100%;
  height: 2px;
  border-top: solid rgb(138, 219, 230) 2px;
}
.link-title {
  margin-left: 10px;
  margin-top: 10px;
  width: 80px;
  height: 2px;
  border-top: solid rgb(172, 176, 177) 2px;
}
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
